import base from './base';
import vm from '@/main';

export default class auth extends base {
    /**
* [getAuthList 获取权限组列表]
*
* @return  {[type]}  [return description]
*/
    static getAuthList (params) {
        let url = 'Auth/index';
        return this.get(url, params);
    }

    /**
* [getGroups 获取规则列表]
*
* @return  {[type]}  [return description]
*/
    static getRuleList (params) {
        let url = 'Auth/getRuleList';
        return this.get(url, params).then(data => {
            // vm.$Message.success(data.msg);
            return data;
        }).catch(error => {
            vm.$Message.error(error.message);
            console.error(error);
            throw error;
        });
    }

    /**
* [delUser 删除权限]
*
* @return  {[type]}  [return description]
*/
    static delAuth (params) {
        let url = 'Auth/del';
        return this.get(url, params, true).then(data => {
            vm.$Message.success(data.msg);
        }).catch(error => {
            vm.$Message.error(error.message);
            console.error(error);
            throw error;
        });
    }

    /**
* [delUser 删除用户组内用户]
*
* @return  {[type]}  [return description]
*/
    static delMember (params) {
        let url = 'Auth/delMember';
        return this.get(url, params, true).then(data => {
            vm.$Message.success(data.msg);
        }).catch(error => {
            vm.$Message.error(error.message);
            console.error(error);
            throw error;
        });
    }

    /**
* [delUser 获得用户列表]
*
* @return  {[type]}  [return description]
*/
    static getMemberList (params) {
        let url = 'User/getUsers';
        return this.get(url, params).then(data => {
            // vm.$Message.success(data.msg);
            return data;
        }).catch(error => {
            vm.$Message.error(error.message);
            console.error(error);
            throw error;
        });
    }

    /**
* [changeStatus 变更权限状态]
*
* @return  {[type]}  [return description]
*/
    static changeStatus (params) {
        let url = 'Auth/changeStatus';
        return this.get(url, params, true).then(data => {
            vm.$Message.success(data.msg);
        }).catch(error => {
            vm.$Message.error(error.message);
            console.error(error);
            throw error;
        });
    }

    /**
* [modifyUser 修改权限 包括 增加/编辑]
*
* @return  {[type]}  [return description]
*/
    static modifyAuth (url, params) {
        return this.post(url, params, true).then(data => {
            vm.$Message.success(data.msg);
        }).catch(error => {
            vm.$Message.error(error.message);
            console.error(error);
        });
    }
}
